package cn.jwcat.service.impl;

import cn.jwcat.entity.Notice;
import cn.jwcat.mapper.NoticeMapper;
import cn.jwcat.service.INoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 公告 服务实现类
 * </p>
 *
 * @author 橙子味的猫
 * @since 2023-04-09
 */
@Transactional
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

	@Override
	public List<Notice> inquiry(Notice notice) {
		String title = notice.getTitle();
		String context = notice.getContext();
		String[] time = notice.getTime();
		String startTime = null;
		String endTime = null;
		if (time.length != 0) {
			startTime = time[0];
			endTime = time[1];
		}
		return this.baseMapper.inquiry(title, context, startTime, endTime);
	}

	@Override
	public List<Notice> getNoticeLastSix() {
		LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();
		wrapper.orderByDesc(Notice::getCreateTime).last("limit 6");
		return this.list(wrapper);
	}
}
